home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Development Platforms / Apple II / Essentials / Technical.Notes / IIGS / TN.IIGS.003 < prev    next >
Encoding:
Text File  |  1991-01-11  |  17.2 KB  |  464 lines  |  [TEXT/pdos]

  1. Apple II
  2. Technical Notes
  3. _____________________________________________________________________________
  4.                                                   Developer Technical Support
  5.  
  6.  
  7. Apple IIGS
  8. #3:    Window Information Bar Use
  9.  
  10. Revised by:    Dave Lyons                                        January 1991
  11. Written by:    Dan Oliver                                        October 1986
  12.  
  13. This Technical Note details the use of a window's information bar, includinga
  14. code sample which places a menu in an information bar.
  15. Changes since November 1988:  Added a note about the current Resource
  16. Application when inside an InfoDefProc procedure, and information about
  17. information bars and NewWindow2.
  18.  
  19. _____________________________________________________________________________
  20.  
  21. Apple IIGS window information bars are not as straightforward as other window
  22. features, and one reason for this is the small amount of space originally
  23. allocated for their processing.  If you feel your application can benefitfrom
  24. the use of information bars, you can implement them, and this Technical Note
  25. explains how to do it and includes some suggestions for their use.  The code
  26. samples below demonstrate how to place a menu bar in an information bar, but
  27. your use of information bars is not limited to those described here.
  28.  
  29.  
  30. Information Bar Initialization
  31.  
  32. You can create an information bar in a window when you create the window by
  33. setting the following fields in the parameter list you pass to NewWindow:
  34.  
  35. wFrame          Set bit 4.
  36.  
  37. wInfoHeight     Set to the height of the information bar (should not exceed
  38.                 window height).
  39.  
  40. wInfoDefProc    Set to the address of the information bar definition
  41.                 procedure (see below).
  42.  
  43. If you create a window as visible, the Window Manager will call your
  44. information bar definition procedure (InfoDefProc) before returning from
  45. NewWindow.  If you have to create the contents of the information bar after
  46. the window, you will have a problem since the Window Manager will expect your
  47. InfoDefProc to draw things which do not yet exist.  You can solve this problem
  48. by creating the window as invisible, creating the contents of the information
  49. bar, then showing the window.  Another solution would be to detect, in the
  50. InfoDefProc, that the contents of the information bar do not yet exist.
  51.  
  52. NewWindow2, however, does not let you override the information bar drawing
  53. procedure in the template.  If you pass a window template in a resource,
  54. creating the window as visible crashes (since the address of your information
  55. bar drawing procedure cannot possibly be in the window template resource).
  56. Instead, create the window as invisible and call SetInfoDraw to set the address
  57. of the information bar drawing procedure before calling ShowWindow.
  58.  
  59. Below is an example of initializing a window's information bar to contain a
  60. menu bar.  The three key fields of the parameter list which you pass to
  61. NewWindow are as follows:
  62.  
  63. wFrame          Set bit 4 = 1 and bit 5 = 0 for an invisible window; the
  64.                 other bits do not affect the information bar, so you can set
  65.                 them as you wish.
  66.  
  67. wInfoHeight     Assuming you are using a system menu bar and initializing it
  68.                 before the window, set to the height FixMenuBar returned
  69.                 when you created the system menu bar.  If you would rather
  70.                 use an absolute value, which we do not advise, you could use
  71.                 14 which should be about right for the current system font.
  72.  
  73. wInfoDefProc    Set to the address of the InfoDefProc, in this case
  74.                 draw_info.
  75.  
  76. After you create the window, but before you show it, you can create the menu
  77. bar to place in the information bar.  The code to create the menu bar might
  78. look like the following:
  79.  
  80. window        Direct page location that contains pointer to window's port.
  81. ;
  82. ; --- Create a menu bar
  83. --------------------------------------------------------------------
  84. ;
  85.         pha                             Space for result.
  86.         pha
  87.         pea    $FFFF                    Set "use current port" flag.
  88.         pea    $FFFF
  89.         _NewMenuBar                     Create a menu bar.
  90.         pla                             Get returned menu bar handle.
  91.         sta    <menuBar                 Remember menu bar handle.
  92.         pla
  93.         sta    <menuBar+2
  94. ;
  95. ;
  96. ; --- Store menu bar's handle in the window's InfoRefCon
  97. -----------------------------------
  98. ;
  99.         pei    <menuBar+2               Pass menu bar handle.
  100.         pei    <menuBar
  101.         pei    <window+2                Window to set refCon.
  102.         pei    <window
  103.         _SetInfoRefCon                  Store menu bar handle in window's
  104. infoRefCon.
  105. ;
  106. ;
  107. ; --- Make the window's menu bar the current menu bar
  108. --------------------------------------
  109. ;
  110.         pei    <menuBar+2               Pass menu bar handle.
  111.         pei    <menuBar
  112.         _SetMenuBar                     Make new menu bar the current menu bar.
  113.  
  114. ;
  115. ;
  116. ; --- Get the RECT of the window's information bar
  117. -----------------------------------------
  118. ;
  119.         pea    tempRect|-16             Pass pointer of RECT.
  120.         pea    tempRect
  121.         pei    <window+2                Pass pointer of window.
  122.         pei    <window
  123.         _GetRectInfo                    tempRect = interior RECT of window's
  124. Info Bar.
  125.  
  126.  
  127. ; --- Dereference menu bar handle
  128. ----------------------------------------------------------
  129. ;
  130.         ldy    #2
  131.         lda    [menuBar],y
  132.         tay
  133.         lda    [menuBar]
  134.         sta    <menuBar                 Now menuBar is the pointer to the Menu
  135. Bar.
  136.         sty    <menuBar+2
  137. ;
  138. ;
  139. ; --- Set size of menu bar
  140. -----------------------------------------------------------------
  141. ;
  142. ;
  143.         lda    <tempRect+y1
  144.         dec    a                        Overlap top side.
  145.         ldy    #CtlRect+y1
  146.         sta    [menuBar],y
  147. ;
  148.         lda    <tempRect+x1
  149.         dec    a                        Overlap left side.
  150.         ldy    #CtlRect+x1
  151.         sta    [menuBar],y
  152. ;
  153.         lda    <rect+y2
  154.         inc    a                        Overlap bottom side.
  155.         ldy    #CtlRect+y2
  156.         sta    [menuBar],y
  157. ;
  158. ;
  159. ; --- Set flag to tell Menu Manager to draw menu in current port
  160. ---------------------------
  161. ;
  162.         ldy    #CtlOwner+2              Set high bit in CtlOwner.
  163.         lda    [menuBar],y
  164.         ora    #$8000
  165.         sta    [menuBar],y
  166. ;
  167. ;
  168. ; --- Create the menus and add them to the window's menu bar
  169. -------------------------------
  170. ;
  171.         lda    #4
  172. loop    pha                             Save index into menu list.
  173.         tay                             Switch index to Y.
  174. ;
  175.         pha                             Space for return value.
  176.         pha
  177.         lda    menu_list+2,y            Pass address of menu/item lines.
  178.         pha
  179.         lda    menu_list,y
  180.         pha
  181.         _NewMenu
  182. ;                                       Menu handle already on stack.
  183.         pea    0                        Insert menu list at front of list.
  184.         _InsertMenu                     Add my menus to the system menu bar.
  185. ;
  186.         pla
  187.         sec
  188.         sbc    #4
  189.         bpl    loop
  190. ;
  191. ;
  192. ; --- Initialize the size of the menu bar and menus
  193. ----------------------------------------
  194. ;
  195.         pha                             Space for returned bar height.
  196.         _FixMenuBar                     Fix up positions in the menu bar.
  197.         pla                             Discard height of menu bar.
  198. ;
  199. ;
  200. ; --- Restore the system menu bar as the current menu
  201. --------------------------------------
  202. ;
  203.         pea    0                        Pass flag for system menu bar.
  204.         pea    0
  205.         _SetMenuBar                     Make system menu bar current.
  206.  
  207. The window's menu bar is now initialized, and you can make the window visible
  208. with a call to ShowWindow; the InfoDefProc will draw the menu bar.
  209.  
  210.  
  211. Information Bar Definition Procedure (InfoDefProc)
  212.  
  213. The InfoDefProc is slightly misleading; it is only responsible for drawing the
  214. interior, above the background, of the information bar.  The InfoDefProc is not
  215. responsible for defining the information bar, drawing the frame and background,
  216. testing for hits, or tracking the user.  The InfoDefProc is located inside your
  217. application, and the Window Manager calls it whenever it needs to draw the part
  218. of the window frame that contains the information bar. 
  219. Each window with an information bar can have its own InfoDefProc, or they can
  220. all share a common InfoDefProc.  When the Window Manager calls your InfoDefProc,
  221. it sets the proper port, the Window Manager's port, and the proper state, an
  222. origin local to the window frame and clipped to any windows above it.  The
  223. direct page and data bank are not defined and should be considered unknown.
  224.  
  225. The Window Manager passes your InfoDefProc the following information:
  226.  
  227.   o  Pointer to the information bar's interior rectangle (less frame), local
  228.      coordinates.
  229.   o  Value of the window's wInfoRefCon, set and used only by your application.
  230.   o  Pointer to the window's port (do not switch to this port for drawing).
  231.  
  232. A window that has an information bar containing a menu bar (handle stored in the
  233. window's InfoRefCon) might have a InfoDefProc as follows:
  234.  
  235. draw_info    START
  236. ;
  237. theWindow    equ  6            Offset to the information bar owner window
  238. infoRefCon   equ  theWindow+4  Offset to the window's information bar RefCon
  239. infoRect     equ  infoRefCon+4 Offset to the information bar's enclosing RECT
  240. ;
  241.         phd                    Save original direct page.
  242.         tsc                    Switch to direct page in stack.
  243.         tcd
  244. ;
  245. ;
  246. ; --- Draw the window's menu bar in the window's information bar
  247. ---------------------------
  248. ;
  249.         pei    infoRefCon+2    Pass handle of window's menu bar handle.
  250.         pei    infoRefCon
  251.         _SetMenuBar            Make the window's menu bar the current menu
  252.                                bar.
  253. ;
  254.         _DrawMenuBar           Draw the window's menu bar, as requested.
  255. ;
  256.         lda    #0              Zero is the flag for the system menu bar.
  257.         pha
  258.         pha
  259.         _SetMenuBar            Make the system menu bar current again.
  260. ;
  261. ;
  262. ; --- Remove input parameters from the stack
  263. -----------------------------------------------
  264. ;       ldx    #12
  265.         ply                     Pull original direct page, save in Y.
  266. ;
  267.         tsc                     Move direct page point to stack.
  268.         tcd
  269.         lda    2,s              Move return address over input parameters.
  270.         sta    2,x
  271.         lda    0,s
  272.         sta    0,x
  273. ;
  274.         tsc                      Adjust stack for stripped input parameters.
  275.         phx                      Number of bytes of input parameters.
  276.         clc
  277.         adc    1,s               Add number of input parameters to stack
  278.                                  pointer.
  279.         tcs                      And reset stack.
  280. ;
  281.         tya                      Restore original direct page.
  282.         tcd
  283. ;
  284.         rtl                      Return to Window Manager.
  285.         END
  286.  
  287.  
  288. Information Bar Environment
  289.  
  290. An information bar is part of a window's frame, that is, not part of the
  291. window's content region.  Because it is part of the frame, an information bar
  292. is in the Window Manager's port, so before an interaction (drawing or mouse
  293. selecting), the proper port (Window Manager's) must be in the proper state.
  294. The proper state means the origin must be at the window's upper-left corner
  295. and clipped to any windows above.
  296.  
  297. When the Window Manager calls the InfoDefProc it sets the proper port to the
  298. proper state; however, to interact with the information bar outside the
  299. InfoDefProc, you must set the proper port the the proper state.  You can
  300. accomplish this with a call to StartInfoDrawing.  When the interaction is
  301. completed, you must allow the Window Manager to return its port to a general
  302. state via a call to EndInfoDrawing.  You are in a special state that requires
  303. some constraints (discussed later) between the calls to StartInfoDrawing and
  304. EndInfoDrawing.
  305.  
  306. Here is an example of interacting with our window's menu bar.
  307.  
  308. ;
  309. poll    pha                             Space for return value.
  310.         pea    %0000111101101110        Pass event mask to use.
  311.         pea    TaskRec|-16              Pass pointer to Task record.
  312.         pea    TaskRec
  313.         _TaskMaster
  314.         pla                             Get returned value.
  315.         beq    poll                     Does event need further processing?
  316. ;
  317. ;
  318. ; --- Handle button down in window's information bar
  319. ---------------------------------------
  320. ;
  321.         cmp    #InInfo                  In Information bar?
  322.         bne    poll
  323. ;
  324.         pha                             Space for result.
  325.         pha
  326.         lda    TaskRec+TaskData+2       Pass pointer of window.
  327.         pha
  328.         lda    TaskRec+TaskData
  329.         pha
  330.         _GetInfoRefCon                  Get menu bar handle from window's
  331.                                         InfoRefCon.
  332.         pla
  333.         sta    menuBar
  334.         pla
  335.         sta    menuBar+2
  336. ;
  337. ;
  338. ; --- Switch to proper port in proper coordinate system
  339. ------------------------------------
  340. ;
  341.         pea    tempRect|-16             Pass pointer to RECT to store info
  342.                                         bar RECT.
  343.         pea    tempRect
  344.         lda    TaskRec+TaskData+2       Pass pointer of window.
  345.         pha
  346.         lda    TaskRec+TaskData
  347.         pha
  348.         _StartInfoDrawing
  349. ;
  350. ;
  351. ; --- Handle menu selection from window's menu bar
  352. -----------------------------------------
  353. ;
  354.         pea    TaskRec|-16              Pass pointer to Task record for
  355.                                         MenuSelect.
  356.         pea    TaskRec
  357.         pei    menuBar+2                Pass handle of menu bar.
  358.         pei    menuBar
  359.         _MenuSelect                     Let user make selection.
  360. ;
  361.         lda    event+TaskData           Get the item's ID number.
  362.         beq    exit                     Was a selection made?
  363. ;
  364.         _EndInfoDrawing                 Switch back to original port.
  365.  
  366. ;
  367. ;         (Handle the menu selection.)
  368. ;
  369. ;    The EndInfoDrawing followed by the StartInfoDrawing call is only
  370. ;    needed when code between them calls the Window Manager.
  371. ;
  372.         pea    tempRect|-16             Pass pointer to RECT to store info      
  373.      bar RECT.
  374.         pea    tempRect
  375.         lda    TaskRec+TaskData+2       Pass pointer of window.
  376.         pha
  377.         lda    TaskRec+TaskData
  378.         pha
  379.         _StartInfoDrawing               Switch to the proper port in the        
  380.      proper state.
  381. ;
  382.         pea    0                        Pass unhilite flag.
  383.         lda    TaskRec+TaskData+2       Pass menu's ID number.
  384.         pha
  385.         _HiliteMenu                     Unhilite menu's title.
  386. ;
  387. ;
  388. ; --- Clean up and return to polling
  389. -------------------------------------------------------
  390. ;
  391. exit    _EndInfoDrawing                 Switch back to original port.
  392. ;
  393.         pea    0                        Make system menu bar current.
  394.         pea    0
  395.         _SetMenuBar
  396. ;
  397.         jmp    poll                     Return to polling user.
  398. ;
  399.  
  400.  
  401. Information Bar Shutdown
  402.  
  403. When the Window Manager closes the window, it is up to you to resolve any
  404. shutdown necessities associated with the information bar.  Using our window
  405. menu bar example, the close window might look like the following:
  406.  
  407. ;
  408.         pei    menuBar+2                Pass handle of menu bar
  409.         pei    menuBar
  410.         _SetMenuBar
  411. ;
  412.         pha                             Space for returned menu handle.
  413.         pha
  414.         pea    2                        ID number of second menu.
  415.         _GetMHandle                     Get the menu's handle.
  416.         _DisposeMenu                    Free menu record and associated data.
  417. ;
  418.         pha                             Space for returned menu handle.
  419.         pha
  420.         pea    1                        ID number of first menu.
  421.         _GetMHandle                     Get the menu's handle.
  422.         _DisposeMenu                    Free menu record and associated data.
  423. ;
  424.         pea    0                        Make system menu bar current.
  425.         pea    0
  426.         _SetMenuBar
  427. ;
  428.         pha                             Space for menu bar's handle.
  429.         pha
  430.         pei    <window+2                Pass pointer of window to close.
  431.         pei    <window
  432.         _GetInfoRefCon                  Get the InfoRefCon from the window.
  433.         _DisposeHandle                  Free menu bar record.
  434. ;
  435.         pei    <window+2                Pass pointer of window to close.
  436.         pei    <window
  437.         _CloseWindow                    Now the window can be closed.
  438. ;
  439.  
  440. The type of shutdown you use depends upon the contents of the informationbar.
  441.  
  442. Why didn't I put a DisposeMenuBar call in the Menu Manager?  I didn't thinkof it
  443. until a week too late.  Sorry.
  444.  
  445.  
  446. Other Information Bar Uses
  447.  
  448. The following suggestions are only theories and have not been tested.
  449.  
  450.   o  Display text information, as in Macintosh Finder windows.
  451.   o  Split window.  Like the content region, the information bar could be large
  452.      enough to hold data.
  453.   o  Hold controls.  You could scroll data in the content region while keeping
  454.      the controls which affect the display in place and within the user's reach.
  455.      (Note:  The Control Manager currently will not allow controls it creates in
  456.      an information bar.  In this case, NewControl would be using a port that is
  457.      not in your window's port, namely the Window Manager's port.)
  458.  
  459.  
  460. Further Reference
  461. _____________________________________________________________________________
  462.   o  Apple IIGS Toolbox Reference, Volumes 1 & 2
  463.  
  464.